//
//  TextfiledView.m
//  IWaneHome
//
//  Created by hwd on 印度历1938/6/8.
//  Copyright © 印度历1938年 hwd_zlg. All rights reserved.
//

#import "TextfiledView.h"
@interface TextfiledView ()<UITextFieldDelegate,UITextViewDelegate>

@property (nonatomic,assign) BOOL isOpen;

@property (nonatomic,strong) UIButton *showBtn;

@end
@implementation TextfiledView

-(void)addShowTextfiledViewImage:(UIImage *)image Tittle:(NSString *)title Number:(NSInteger)number Show:(BOOL)show
{
   
    self.backgroundColor = [UIColor clearColor];
    [self.layer setCornerRadius:5];
    self.layer.masksToBounds = YES;
    
    UIImageView *headerImageV = [[UIImageView alloc]initWithFrame:CGRectMake(30*screenW_6,(self.frame.size.height-25*screenW_6)/2 , 25*screenW_6, 25*screenW_6)];
    headerImageV.image = image;
    [self addSubview:headerImageV];
    
    
    _inputTf = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(headerImageV.frame)+15*screenW_6,2*screenW_6,self.frame.size.width-100*screenW_6,self.frame.size.height-1*screenW_6)];
    _inputTf.font = [UIFont systemFontOfSize:16*screenW_6];
    _inputTf.delegate = self;
    _inputTf.returnKeyType =  UIReturnKeyDefault;
    _inputTf.placeholder = title;
    _inputTf.textColor = [UIColor whiteColor];
    [_inputTf setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    [self addSubview:_inputTf];
    
    if (show)
    {
        _showBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _showBtn.frame = CGRectMake(self.frame.size.width-45*screenW_6,self.frame.size.height/2-10*screenW_6, 20*screenW_6, 20*screenW_6);
        [_showBtn setImage:kImg(@"eyes") forState:UIControlStateNormal];
        [_showBtn setImage:kImg(@"eye") forState:UIControlStateSelected];
        [_showBtn addTarget:self action:@selector(changePasswordStatus) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_showBtn];
        
        _inputTf.secureTextEntry = YES;
    }
    
    
    _lineLab =[ToolViewViewController addLineLab:CGRectMake(25*screenW_6,self.frame.size.height-1*screenW_6,self.frame.size.width-50*screenW_6, 1*screenW_6)];
    
    [self addSubview:_lineLab];

}

- (void)changePasswordStatus
{
    
    if (_isOpen == NO)
    {
        _inputTf.secureTextEntry = YES;
        _showBtn.selected = YES;
    }
    else
    {
        _inputTf.secureTextEntry = NO;
        _showBtn.selected = NO;
    }
    _isOpen = !_isOpen;
}


-(BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
    self.block(textField.text,_type);
    return YES;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [_inputTf resignFirstResponder];
    return YES;
}




@end
